import VueRouter from "vue-router";
import cookie from "../cookie/index";
import storage from '../model/storage'
import store from "../store";
// 主页面
// import Admin from "../pages/Admin";
import Personal from "../pages/Personal";
import PersonalShop from "../pages/PersonalShop";
import Orderindex from "../pages/Orderindex.vue";

import MainBoxRight from "../components/ly/MainBoxRight";
import Information from "../components/ly/Information";

// 李典
import Index from "../pages/Index.vue";
import Hotel from "../pages/Hotel.vue";
import Cate from "../pages/Cate.vue";
import Dining from "../pages/Dining.vue";
import HomeStay from "../pages/HomeStay.vue";
import ApplyShop from "../pages/ApplyShop.vue";
import Search from "../pages/Seach.vue"

import MainRightFramework from "../components/ly/MainRightFramework";
import ShopPicture from "../components/ly/ShopPicture";
import ShopMain from "../components/ly/ShopMain";
const router = new VueRouter({
  mode: "history",
  routes: [
    {
      name: "main",
      path: "/",
      component: Index,
      meta: { show: false },
    },
    {
      name: "dianpu",
      path: "/applyShop",
      component: ApplyShop,
      meta: { show: true },
    },
    {
      name: "bingguan",
      path: "/hotel",
      component: Hotel,
      meta: { show: true },
    },
    {
      name: "meishi",
      path: "/cate/:id",
      component: Cate,
    
      meta: { show: true },
    },
    {
      name: "canting",
      path: "/dining/:tag",
      component: Dining,
      meta: { show: true },
    },
    {
      name: "minsu",
      path: "/homeStay",
      component: HomeStay,
    },
    {
      path: "/search",
      component:Search,
      meta: { show: true },
    },
    {
      // 个人中心
      path: "/personal",
      component: Personal,
      meta: { show: true },
      children: [
        {
          path: "",
          component: MainBoxRight,
        },
        {
          // 修改个人中心
          path: "information",
          component: Information,
        },
        {
          // 实名认证
          path: "IDCard",
          component: () => import("../components/ly/IDCard.vue"),
        },
        {
          // 我的足迹
          name: "myfootmark",
          path: "myfootmark",
          component: MainRightFramework,
        },
        {
          // 我的收藏
          name: "mycollect",
          path: "mycollect",
          component: MainRightFramework,
        },
        {
          // 我的优惠券
          name: "mycoupon",
          path: "mycoupon",
          component: MainRightFramework,
        },
        {
          // 预约
          path: "order",
          component: MainRightFramework,
          children: [
            {
              name: "AllOrder",
              path: "status=0",
              component: MainRightFramework,
            },
            {
              name: "OverOrder",
              path: "status=1",
              component: MainRightFramework,
            },
            {
              name: "Ordering",
              path: "status=2",
              component: MainRightFramework,
            },
            {
              name: "AssessOrder",
              path: "status=3",
              component: MainRightFramework,
            },
          ],
        },
      ],
    },
    {
      // 店铺
      path: "/shoppersonal",
      component: PersonalShop,
      meta: { show: true },
      children: [
        {
          name: "myshop",
          path: "",
          component: ShopMain,
        },
        {
          // 修改商家基本信息
          name: "Shopinformation",
          path: "information",
          component: () => import("../components/ly/Shopinformation.vue"),
        },
        {
          // 修改封面
          name: "ShopPicture",
          path: "picture",
          component: ShopPicture,
        },
        {
          // 上下架优惠券管理
          name: "coupon",
          path: "coupon",
          component: () => import("../components/ly/ShopCoupon.vue"),
        },
        {
          // 发布动态
          name: "dynamic",
          path: "dynamic",
          component: () => import("../components/ly/ShopDynamic.vue"),
        },
        {
          // 店铺订单管理
          name: "shoporder",
          path: "shoporder",
          component: () => import("../components/ly/ShopOrder.vue"),
        },
      ],
    },
    {
      name: "order",
      path: "/order",
      component: Orderindex,
      meta: { show: true },
    },
    //后台
    {
      path: "/admin",

      redirect: "/login",
      component: () => import("../pages/Admin"),
      meta: { 
        show: true,
        admin: true
      },
      children: [
        {
          path: "",
          name: "home",
          component: () => import("../components/lzq/AdminHome"),
        },
        //用户管理
        {
          path: "userManage/userList",
          name: "userList",
          component: () => import("../components/lzq/UserManage"),
        },
        {
          path: "userManage/userBaned",
          name: "userBaned",
          component: () => import("../components/lzq/UserClose"),
        },
        //店铺管理
        {
          path: "shopManage/shopList",
          name: "shopList",
          component: () => import("../components/lzq/shopManage"),
        },
        {
          path: "shopManage/shopBaned",
          name: "shopBaned",
          component: () => import("../components/lzq/shopClose"),
        },
        {
          path: "shopManage/shopAppeal",
          name: "shopAppeal",
          component: () => import("../components/lzq/shopAppeal"),
        },
        //标签管理
        {
          path: "tagManage",
          name: "tagManage",
          component: () => import("../components/lzq/tagManage"),
        },
        //管理员管理
        {
          path: "adminManage",
          name: "adminManage",
          component: () => import("../components/lzq/adminManage"),
        },
        {
          path: "adminInfo",
          name: "adminInfo",
          component: () => import("../components/lzq/adminInfo"),
        },
        //商家管理
        {
          path: "shopperManage/shopperList",
          name: "shopperList",
          component: () => import("../components/lzq/shopperList"),
        },
        {
          path:'shopperManage/shopperCheck',
          name:'shopperCheck',
          component: () => import('../components/lzq/shopperCheck')
        },
        //系统管理
        {
          path:'systemManage/annoList',
          name:'annoList',
          component: () => import('../components/lzq/annoList')
        },
        {
          path:'systemManage/loginRecord',
          name:'loginRecord',
          component: () => import('../components/lzq/loginRecord')
        },
        //图片管理
        {
          path:'imageManage/carouselList',
          name:'carouselList',
          component: () => import('../components/lzq/carouselList')
        },
        {
          path:'imageManage/adverList',
          name:'adverList',
          component: () => import('../components/lzq/adverList')
        }
      ],
    },
    //普通登录
    {
      path: "/login",
      name: "login",
      meta: { show: true },
      component: () => import("../pages/Login.vue"),
    },
    //普通注册
    {
      path:'/register',
      name:'register',
      meta:{show:true},
      component: () => import("../pages/register.vue")
    },
    //找回密码
    {
      path:'/findPassword',
      name:'findPassword',
      meta:{show:true},
      component:()=>import("../pages/findPassword.vue")
    },
    //邮箱登录注册
    {
      path: "/emailLogin",
      name: "emailLogin",
      meta: { 
        show: true 
        
      },
      component: () => import("../pages/emailLogin.vue"),
    },
  ],
});
router.beforeEach((to, from, next) => {
  if (to.path === "/login" || to.path === "/" || to.path === "/emailLogin") {
    next();
  } else {
    let token = storage.get('token') ? storage.get('token'):store.state.token
    if (
      token === null ||
      token === "" ||
      token === "undefined" ||
      token === undefined
    ) {
      console.log(1111111);
      next("/login");
    } else {
      next();
    }
  }
});

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  undefined;
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};

export default router;
